package com.kly.juc.blockqueue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @author admin
 * @date 2025/4/18
 */
public class BlockingQueueDemo {

    public static void main(String[] args) {
        ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(15);
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                queue.add("面条");
            }).start();
        }

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        while (!queue.isEmpty()) {
            new Thread(() -> {
                String food = queue.poll();
                System.out.println("拿到食物：" + food);
            }).start();
        }
    }
}
